﻿using System;
using System.Collections.Generic;
using System.Web.Mvc;
using ControleRepresentante.Logic.Models;
using ControleRepresentante.Logic.Repositories;
using WebSite.Controllers;
using WebSite.Controllers.ControllerExtensions;
using WebSite.ViewModels.DetailsViewModels;
using WebSite.ViewModels.EditViewModels;
using WebSite.ViewModels.Fields;

namespace ControleRepresentante.UnitTests.Mocks
{
    internal class MockController : UsuariosHolderControllerBase<MockRepository, MockModel, MockStatistics>
    {
        internal const Area AreaUsed = Logic.Models.Area.Mock;

        private readonly AttributeType m_AttributeType;
        private readonly List<IField> m_SearchFields;

        public MockController(AttributeType attributeType, IRepositoryProvider repositoryProvider, ISessionConfiguration sessionConfiguration, IControllerExtensionProvider controllerExtensionProvider)
            : base(repositoryProvider, sessionConfiguration, controllerExtensionProvider)
        {
            m_AttributeType = attributeType;
            m_SearchFields = new List<IField>();
        }

        protected override IAttributeHolderIndexViewModel GetAttributeHolderIndexViewModel(MockStatistics statistics)
        {
            MockIndexViewModel attributeHolderIndexViewModel = new MockIndexViewModel();
            foreach (IField field in m_SearchFields)
            {
                attributeHolderIndexViewModel.AddSearchField(field);
            }
            return attributeHolderIndexViewModel;
        }

        protected override AttributeHolderEditViewModel GetEditViewModel()
        {
            return new MockEditViewModel();
        }

        protected override AttributeType AttributeType { get { return m_AttributeType; } }

        protected override string CreateForActionName
        {
            get { throw new NotImplementedException(); }
        }

        protected override UsuariosHolderDetailsViewModel DoGetUsuariosHolderDetailsViewModel(MockModel model)
        {
            return new MockDetailsViewModel();
        }

        public void AddSearchField(IField field)
        {
            m_SearchFields.Add(field);
        }

        protected override Area? Area { get { return AreaUsed; } }

        public ModelStateDictionary CommitEdit(FormCollection formCollection)
        {
            ExtensionsUpdateModel(formCollection);
            return ModelState;
        }
    }
}